<?php
$isReloadable = true;
require_once("../../pers/inc.config.php");
require_once(OVF_FS_WEB_ROOT.'/app/_inc/inc.session.php');
require_once(OVF_FS_WEB_ROOT.'/app/_inc/funct.html.php');
$objSess->setReqSV('agenda', 'dataAge', date('d/m/Y'));

$sSql = "SELECT a.*, au.id_utente, u.nome, u.cognome "
	.", ti.descr AS TI_des, ti.pallino AS TI_pallino "
	.", an.intestaz1 "
	." FROM ovf_agenda a "
	." LEFT JOIN ovf_agenda_utenti au ON au.id_agenda = a.id_agenda "
	." LEFT JOIN ovf_utenti u ON u.id_utente = au.id_utente "
	." LEFT JOIN ovf_agenda_tipi_imp ti ON ti.id_tipo_imp = a.id_tipo_imp \n"
	." LEFT JOIN ovf_anagrafiche an ON an.id_anag = a.id_anag \n"
	." WHERE a.id_agenda = ".reqVarInt('id');
$objDB->query($sSql,'selAge');	
if (!$acAge = $objDB->fetch('selAge')) {
	backOnErr("id '".reqVar('id')."' errato");
}
$acX = $acAge;
$aAgende = array();
while($acX) {
	$aAgende[$acX['id_utente']] = $acX['nome']." ".$acX['cognome'];
	$acX = $objDB->fetch('selAge');
}
$agendeTxt = implode(", ",$aAgende);

if (reqVar('azione') == 'elimina') {
	$msgPag = confEli();
} else {
}
$aOre = array('08'=>'08','09'=>'09','10'=>'10','11'=>'11','12'=>'12','13'=>'13','14'=>'14','15'=>'15'
	,'16'=>'16','17'=>'17','18'=>'18','19'=>'19','20'=>'20','21'=>'21','22'=>'22','23'=>'23'
	,'00'=>'00','01'=>'01','02'=>'02','03'=>'03','04'=>'04','05'=>'05','06'=>'06','07'=>'07');
$aMin = array('00'=>'00','15'=>'15','30'=>'30');
$aDur[''] = "-- seleziona durata --";
$aDur[9999] = "intera giornata";
$aDur[15] = "15 min.";
$aDur[30] = "30 min";
$aDur[45] = "45 min";
$aDur[60] = "1 ora";
$aDur[75] = "1 ora e 15 min.";
$aDur[90] = "1 ora e 30 min.";
$aDur[105] = "1 ora e 45 min.";
$aDur[120] = "2 ore";
$aDur[150] = "2 ore e 30 min.";
$aDur[180] = "3 ore";
$aDur[210] = "3 ore e 30 min.";
$aDur[240] = "4 ore";
$aDur[300] = "5 ore";
$aDur[360] = "6 ore";
$aDur[420] = "7 ore";
$aDur[480] = "8 ore";
$aPOP = array('pub'=>'pubblico','occ'=>'occupato','pri'=>'privato');

$sCmdR = '';
$sCmdR .= "&nbsp;&nbsp;&nbsp;";
$sCmdR .= "<a class=\"cmd1\" href=\"javascript:confEli();\" >elimina</a>\n";
$sCmdR .= "&nbsp;&nbsp;&nbsp;";
$sCmdR .= "<a class=\"cmd1\" href=\"javascript:goModif();\" >modifica</a>\n";
$sCmdR .= cmdTorna('torna'); 

testaHtml('Agenda','Visualizza impegno',$msgPag,'agen');
?>
<script type="text/javascript">
<!--
function goModif() {
	document.frm1.action = 'impeMod.php';
	document.frm1.submit();	
}
function confEli() {
	if (confirm("confermi l'eliminazione ?")) {
		document.frm1.azione.value = 'elimina';
		document.frm1.submit();
	}
}
//-->
</script>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="right"><?php echo $sCmdR;?></td>
   </tr>
</table>
<?=getHtmlForm('frm1','',array('enctype'=>true));?>
<?=getHtmlHidden('azione','');?>
<?=getHtmlHidden('id');?>
<?=getHtmlHidden('xsn',XSN);?>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<?=getHtmlRigaRif(20);?>
   <tr>
      <td class="tit1" colspan='20' align='center'>Impegno</td>
   </tr>
   <tr>
      <td class="lab1" colspan='3' align='left'>Nell'agenda di</td>
      <td class="txt1" colspan='15' align='left'>
      <?php echo $agendeTxt;?>
		</td>
      <td class="txt1" colspan='2' align='center'>
      	<b><?php echo $aPOP[$acAge['pub_occ_pri']];?></b>
		</td>
   </tr>
   <tr>
      <td class="lab1" colspan='3' align='left'>Oggetto</td>
      <td class="txt1" colspan='12' align='left'>
      	<?php echo $acAge['oggetto']?>
		</td>
      <td class="lab1" colspan='1' align='left'>Dove</td>
      <td class="txt1" colspan='4' align='left'>
      	<?php echo $acAge['dove']?>
		</td>
   </tr>
   <tr>
      <td class="lab1" colspan='3' align='left'>Data</td>
      <td class="txt1" colspan='3' align='left'>
      	<?php echo YMD2DMY($acAge['data_agenda'])?>
		</td>
      <td class="lab1" colspan='1' align='left'>ora</td>
      <td class="txt1" colspan='3' align='left'>
<?php 
	if ($acAge['durata_minuti'] >= 1440) {
		echo "00:00&nbsp;-&nbsp;24:00";
	} else {
		echo lpad($acAge['ora'],2,'0').":".lpad($acAge['minuti'],2,'0')."&nbsp;-&nbsp;";
		$nT = mktime($acAge['ora'],$acAge['minuti'],0,01,01,2001)+$acAge['durata_minuti']*60;
		$sOraFine = date('H:i',$nT);
		if ($sOraFine > "24:00") $sOraFine = "24:00";
		echo $sOraFine;
	}
?>
		</td>
      <td class="lab1" colspan='2' align='left'>Durata</td>
      <td class="txt1" colspan='3' align='left'>
<?php 
if ($acAge['durata_minuti']>=1440) 
	echo 'intera giornata'; 
elseif ($acAge['durata_minuti'] < 60) 
	echo $acAge['durata_minuti']." min.";
elseif ($acAge['durata_minuti'] == 60) 
	echo "1 ora";
elseif ($acAge['durata_minuti'] < 120) 
	echo "1 ora e ".($acAge['durata_minuti']%60)." min.";
elseif (($acAge['durata_minuti']%60) == 0) 
	echo floor($acAge['durata_minuti']/60)." ore";
else 
	echo floor($acAge['durata_minuti']/60)." ore e ".($acAge['durata_minuti']%60)." min.";
?>
		</td>
      <td class="txt1" colspan='5' align='left'>
<? $coloreTi = ($acAge['TI_pallino']=='') ? "trasp" : $acAge['TI_pallino'] ;
echo "<img src=\"".OVF_URL_ROOT."/app/_img/pallino_ti_$coloreTi.gif\" border='0'/>&nbsp;&nbsp;&nbsp;";
echo $acAge['TI_des'];
?>
      </td>
	</tr>
   <tr>
      <td class="lab1" colspan='3' align='left'>Nota</td>
      <td class="txt1" colspan='17' align='left'>
         <?php echo getHtmlViewText($acAge['nota']);?>
		</td>
   </tr>
<?
if ($acAge['intestaz1']) {
?>
   <tr>
      <td class="lab1" colspan='3' align='left'>Azienda</td>
      <td class="txt1" colspan='17' align='left'>
         <a class='txt1' href="../rcom/anag/anagView.php?idAnag=<?=$acAge['id_anag']?>&xsn=<?=XSN?>">
      <?php echo getHtmlViewText($acAge['intestaz1']);?></a>
		</td>
   </tr>
<?
}
?>
</table>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="right"><?php echo $sCmdR;?></td>
   </tr>
</table>
<?
echo "</form>\n";
codaHtml();
exit();

function confEli() {
	return "wip";
}
